package cn.liyicun.school.car2.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

import cn.liyicun.school.car2.base.BaseDriverController;
import cn.liyicun.school.car2.base.LoginDriver;
import cn.liyicun.school.car2.base.LoginUserName;

public class DriverLoginInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {

		if (inv.getController() instanceof BaseDriverController) {
			BaseDriverController line = (BaseDriverController) inv.getController();
			if ("POST".equalsIgnoreCase(line.getRequest().getMethod())) {
				LoginDriver acc = line.getLoginAccount();
				line.verification(acc.getIsDriver() <= 0, "需要先升级为司机!");
				line.verification(acc.getIsDriver() == 2, "司机审批中,请稍等!");
				line.verification(acc.getIsDriver() != 1, "司机状态为禁用!");
			} else {
				LoginDriver acc = line.getLoginAccount(false);
				if (acc == null) {
					line.redirect301("/driver/login", false);
					return;
				} else {
					line.verification(acc.getIsDriver() <= 0, "需要先升级为司机!");
					line.verification(acc.getIsDriver() == 2, "司机审批中,请稍等");
					line.verification(acc.getIsDriver() != 1, "司机状态为禁用!");
				}
			}

		}
		inv.invoke();
	}

}
